#!C:\python25\python.exe
# -*- coding: GB18030 -*-

from string import *
import copy

class CSingleData:
    def __init__(self, strValueName = ' '):
        self.dict = {"group":0,
                     "title":' ',
                     "variable": " ",
                     "justify": ' ',
                     "length": 0,
                     "dotLen": 0,
                     "type":' '
                    }
        self.dict["variable"] = strValueName

    def copy(self):
        return copy.deepcopy(self)

    def __len__(self):
        return len(self.dict)

    def __str__(self):
        str = " "
        for varName in self.dict.keys() :
            if varName != "title" :
                str += "%s|%s  " % (varName, self.dict[varName])
            else :
                pass
                #str += "%s|%s  " % (varName, (self.dict[varName]).decode("GBk"))
        return str

    def clear(self):
        self.dict = {"group" : 0,
                     "title" : ' ',
                     "variable" : ' ',
                     "justify" : ' ',
                     "length" : 0,
                     "dotLen" : 0,
                     "type" : ' '
                    }

    def getValue(self, strIdxName):
        return self.dict[strIdxName]

    def getDict(self) :
        return self.dict

    def setValue(self, strIdxName, Value):
        self.dict[strIdxName] = Value

    def printValue(self):
        #print "CSingleData :  ",
        for varName in self.dict.keys() :
            print " %s|%s  " % (varName, self.dict[varName]) ,
        #print "\n"

class CAllData:
    ''' all the xml data '''
    def __init__(self):
        self.dict = {}

    def clear(self):
        self.dict.clear()

    def getAllData(self):
        return self.dict

    def getAllDataValue(self, strIdxName):
        return self.dict[strIdxName]

    def getSingleValue(self, strIdxName):
        return self.getAllDataValue(strIdxName)[strIdxName]

    def addData(self, strIdxName, dictData):
        if self.dict.has_key(strIdxName) :
            print "exists %s " % strIdxName
            self.printValue()

        if len(dictData) <= 0:
            self.dict[strIdxName] = CSingleData()
        else :
            self.dict[strIdxName] = CSingleData()
            self.dict[strIdxName] = dictData.copy()

    def setValue(self, strIdxName, value):
        self.getAllDataValue(strIdxName)[strIdxName] = value

    def printValue(self):
        print "---CallData: "
        for varName in self.dict.keys() :
            print " %s : " % varName,
            self.dict[varName].printValue()
            #print self.dict[varName]
            print "\n"
